package io.shuttle.mbe.api

import io.shuttle.mbe.api.annotation.ChromeMinVersion
import io.shuttle.mbe.api.types.Value1Function
import io.shuttle.mbe.api.types.Value2Function
import io.shuttle.mbe.core.Promise

////////////////////
// Commands
////////////////////
/**
 * Use the commands API to add keyboard shortcuts that trigger actions in your extension, for example, an action to open the browser action or send a command to the extension.
 *
 * Manifest: "commands"
 */
interface Commands {
    data class Command(
        // The Extension Command description
        val description: String?,
        // The name of the Extension Command
        val name: String?,
        // The shortcut active for this command, or blank if not active.
        val shortcut: String?
    )

    // Returns all the registered extension commands for this extension and their shortcut (if active).
    // Before Chrome 110, this command did not return _execute_action.
    @ChromeMinVersion(96)
    fun getAll(
        callback: Value1Function<List<Command>>? = null
    ): Promise<List<Command>>

    // Fired when a registered command is activated using a keyboard shortcut.
    val onCommand: Events.Event<Value2Function<String, Tabs.Tab>>
}